document.addEventListener('DOMContentLoaded', () => {
    // Add a class to trigger animation when scrolling
    const bookItems = document.querySelectorAll('.book-item');
    
    const observer = new IntersectionObserver((entries) => {
        entries.forEach(entry => {
            if (entry.isIntersecting) {
                entry.target.classList.add('animate');
            }
        });
    }, { threshold: 0.5 });

    bookItems.forEach(item => {
        observer.observe(item);
    });

    // Simple search functionality
    const searchInput = document.createElement('input');
    searchInput.type = 'text';
    searchInput.placeholder = 'Search books...';
    searchInput.classList.add('search-input');

    const headerNav = document.querySelector('header nav');
    headerNav.insertBefore(searchInput, headerNav.firstChild);

    searchInput.addEventListener('input', (e) => {
        const searchTerm = e.target.value.toLowerCase();
        bookItems.forEach(item => {
            const title = item.querySelector('h3').textContent.toLowerCase();
            const author = item.querySelector('p').textContent.toLowerCase();
            if (title.includes(searchTerm) || author.includes(searchTerm)) {
                item.style.display = 'block';
            } else {
                item.style.display = 'none';
            }
        });
    });
});